﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Utils;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Dao;
using Shpm.System;

public partial class App_Input_PersonVstSrh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["PROC_ID"] = Context.Items["SALE_PROC_ID"];
            SaleProcessDao dao = new SaleProcessDao();
            SaleProcessBean beanSP = new SaleProcessBean();
            beanSP.SaleProcId = Convert.ToInt32(ViewState["PROC_ID"]);
            beanSP = dao.FindBySaleProcess(beanSP);
            this.ViewState["CANCEL_FLG"] = beanSP.CancelFlg;
            this.ViewState["CUR_STEP"] = beanSP.CurrentStep;
            if (this.ViewState["PROC_ID"].ToString().Length > 0)
            {
                bindSelectData(this.ViewState["PROC_ID"].ToString());
            }
        }
    }

    protected void lnkTab_Command(object sender, CommandEventArgs e)
    {
        string directUrl = "~/App/Input/SaleProcesseMembershipForm.aspx";
        switch (e.CommandName)
        {
            case "btn0":
                // 新建洽谈
                // this.LinkButton1.CssClass = "selectli";
                // this.LinkButton2.CssClass = "";
                directUrl = "~/App/Input/SaleProcessBeginForm.aspx";
                break;
            case "btn1":
                // 销售管理
                Context.Items["RIGHT"] = "true";
                directUrl = "~/App/Input/PersonVst.aspx";
                break;
            case "btn2":
                // 入住管理
                directUrl = "~/App/Input/MemberForm.aspx";
                break;
            case "btn3":
                // 购卡管理
                directUrl = "~/App/Input/RightPersonForm.aspx";
                break;
            case "btn4":
                // 客户移交
                directUrl = "~/App/Input/ContractHabitationForm.aspx";
                break;
            case "btn1_1":
                // 上门拜访
                directUrl = "~/App/Input/PersonVstSrh.aspx";
                break;
            case "btn1_2":
                // 日常交流
                directUrl = "~/App/Input/PersonTel.aspx";
                break;
            case "btn1_3":
                // 礼品发放
                directUrl = "~/App/Input/SaleProcessPresentForm.aspx";
                break;
            case "btn6":
                // 资格审核
                directUrl = "~/App/Input/SaleProcessIndefinForm.aspx";
                break;
            default:
                break;
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["PROC_ID"])))
        {
            Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        }
        ControllerUtils.Transfer(this.Context, directUrl, false);
    }

    // bind select data by procId
    private void bindSelectData(string procId)
    {
        SaleProcessDao dao = new SaleProcessDao();
        SaleProcessBean beanSP = new SaleProcessBean();
        beanSP.SaleProcId = Convert.ToInt32(procId);
        beanSP = dao.FindBySaleProcess(beanSP);
        if (beanSP != null)
        {
            lblName.Text = beanSP.RelationName;
            lblTel.Text = beanSP.RelationTelephone;
        }
    }

    void Page_PreRender(object sender, EventArgs e)
    {
        if (this.ViewState["PROC_ID"].ToString().Length > 0)
        {
            // 读取一览画面的数据
            SalesProcVisitingDao dao = new SalesProcVisitingDao();
            SalesProcVisitingBean beanV = new SalesProcVisitingBean();
            beanV.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
            IList listV = dao.GetPersonVstList(beanV);
            if (listV.Count > 0)
            {
                for (int i = 0; i < listV.Count; i++)
                {
                    ((SalesProcVisitingBean)listV[i]).RelationCount = Convert.ToString(listV.Count - i);
                }
            }
            viewSrhRst.DataSource = listV;
            viewSrhRst.DataBind();
        }
    }
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

        }
    }
    protected void viewSrhRst_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = viewSrhRst.SelectedRow;
        int IntVal = Convert.ToInt32(((Label)row.Cells[0].FindControl("Label1")).Text);
        Context.Items["ROW_ID"] = IntVal;
        Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        string directUrl = "~/App/Input/PersonVst.aspx";
        ControllerUtils.Transfer(this.Context, directUrl, false);
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        string directUrl = "~/App/Input/PersonVst.aspx";
        ControllerUtils.Transfer(this.Context, directUrl, false);
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        string directUrl = "~/App/Input/SaleCountForm.aspx";
        ControllerUtils.Transfer(this.Context, directUrl, false);
    }
}
